package com.shaw.client.mvc.goal;


import java.util.List;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.google.gwt.user.client.rpc.AsyncCallback;

import com.shaw.client.MailServiceAsync;
import com.shaw.client.TestGxt;

import com.shaw.client.model.Folder;
import com.shaw.client.mvc.AppEvents;



public class MailController extends Controller {

	  private MailServiceAsync service;
	  private MailFolderView folderView;
	  private MailView mailView;

	  public MailController() {
	    registerEventTypes(AppEvents.INIT);
	    registerEventTypes(AppEvents.NavMail);
	    registerEventTypes(AppEvents.ViewMailItems);
	    registerEventTypes(AppEvents.ViewMailItem);
	  }

	  @Override
	  public void handleEvent(AppEvent event) {
	    EventType type = event.getType();
	    if (type == AppEvents.INIT) {
	      forwardToView(folderView, event);
	    } else if (type == AppEvents.NavMail) {
	      forwardToView(folderView, event);
	      forwardToView(mailView, event);
	    } else if (type == AppEvents.ViewMailItems) {
	      onViewMailItems(event);
	    } else if (type == AppEvents.ViewMailItem) {
	      forwardToView(mailView, event);
	    }
	  }

	  private void onViewMailItems(final AppEvent event) {
	    final Folder f = event.getData();
	   
	  }

	  public void initialize() {
	//    service = (MailServiceAsync) Registry.get(TestGxt.SERVICE);

	    folderView = new MailFolderView(this);
	    mailView = new MailView(this);
	  }

	}
